export default {
  namespaced: true,
  state: {
    caseIds: [], // 分配的案件ID
    userIds: [], // 分配的用户
    deptIds: [], // 分配的机构
    mode: "", // 分配模式
    category: "TO_COLLECTOR", // 分配类型
    debt: "NO", // 共债优先分配到同一催收员
    extData: {},
    personalCollectionDays:''
  },
  getters: {
    perviewModel(state) {
      return {
        caseIds: state.caseIds,
        userIds: state.userIds,
        distributeCategory: "TO_COLLECTOR",
        commonFlag: "YES",
        distributeMode: state.mode,
        debt: state.debt,
        personalCollectionDays: state.personalCollectionDays,
        ...state.extData
      };
    },
    distributeModel(state) {
      return {
        caseIds: state.caseIds,
        deptIds: state.deptIds,
        commonFlag: "YES",
        distributeCategory: state.category,
        distributeMode: state.mode,
        analyseId: "",
        distributeNumber: [],
        userIds: state.userIds,
        debt: state.debt,
        personalCollectionDays: state.personalCollectionDays,
        ...state.extData
      };
    }
  },
  mutations: {
    /**
     * 更新分配类型
     * @param state
     * @param category 分配类型
     */
    updateCategory(state, allotType: string) {
      state.category = allotType;
    },
    updateMode(state, mode: string) {
      state.mode = mode;
    },
    updateDeptIds(state, deptId: string) {
      state.deptIds = [deptId];
    },
    updateUserIds(state, userIds: string[]) {
      state.userIds = userIds;
    },
    updateCaseIds(state, caseIds: string[]) {
      state.caseIds = caseIds;
    },
    updateDebtState(state, value: boolean) {
      state.debt = value ? "YES" : "NO";
    },
    // 额外的数据 eg:协催ID
    updateExtData(state, value: object) {
      state.extData = value
    },
    updatePersonalCollectionDays(state,value){
      state.personalCollectionDays = value
    }
  },
  actions: {
    resetState({ commit }) {
      commit("updateCategory", "TO_COLLECTOR");
      commit("updateUserIds", []);
      commit("updateExtData", {});
      commit("updateMode", "BY_INTEGRATE");
    }
  }
};
